package com.ghn.cocknovel.view

import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.GradientDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.PopupWindow
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ghn.cocknovel.R
import com.ghn.cocknovel.ui.activity.map.vm.MapViewModel
import com.kt.NetworkModel.bean.BQueryDriverTransitOrderListBean
import com.kt.NetworkModel.bean.QueryPassengerBySiteBean
import kotlinx.android.synthetic.main.mappopitem.view.*

/**
 *@author: Administrator
 *2023/11/3
 *desc:
 */
class MapOrderPopwindow : PopupWindow {
    val mWorkAdapter by lazy { MapPopAdapter() }

    //    var mMapViewModel: MapViewModel
    var mPopwindowView: View
    var mapActivity: Activity

    constructor(context: Activity, data: QueryPassengerBySiteBean?, mMapViewModel: MapViewModel?) {
        mapActivity = context
//        this.mMapViewModel = mMapViewModel
        mPopwindowView = LayoutInflater.from(context).inflate(R.layout.pop_layout, null, false)
        contentView = mPopwindowView.rootView

        setBackgroundDrawable(ColorDrawable(0))
        //设置SelectPicPopupWindow弹出窗体的宽
        this.width = 500
        //设置SelectPicPopupWindow弹出窗体的高
        this.height = 700
        val mapPopTvZhan = mPopwindowView.findViewById<TextView>(R.id.mapPopTvZhan)


    }


    inner class MapPopAdapter : BaseQuickAdapter<BQueryDriverTransitOrderListBean, BaseViewHolder>, BaseQuickAdapter.OnItemClickListener {
        constructor() : super(R.layout.mappopitem, null) {
            onItemClickListener = this
        }

        @SuppressLint("ResourceType")
        override fun convert(helper: BaseViewHolder?, item: BQueryDriverTransitOrderListBean?) {
            helper?.setText(R.id.popRecyCode, item?.mobileLastFour)
            helper?.setText(R.id.popRecyoriginAddress, item?.originAddress)
            helper?.setText(R.id.popRecydestinationAddress, item?.destinationAddress)
            when (item?.orderStatus) {
                1 -> {
                    helper?.setText(R.id.popRecyorderStatus, "待支付")
                }

                2 -> {
                    helper?.setText(R.id.popRecyorderStatus, "待呼叫")
                }

                3 -> {
                    helper?.setText(R.id.popRecyorderStatus, "呼叫中")
                }

                4 -> {
                    helper?.setText(R.id.popRecyorderStatus, "未上车")
                }

                5 -> {
                    helper?.setText(R.id.popRecyorderStatus, "未上车")
                }

                6 -> {
                    helper?.setText(R.id.popRecyorderStatus, "已上车")
                    val drawable = GradientDrawable()
                    drawable.shape = GradientDrawable.RECTANGLE
                    drawable.gradientType = GradientDrawable.RECTANGLE
                    drawable.cornerRadius = 10f
                    drawable.setColor(mContext.getColor(R.color.green3))
                    helper?.itemView?.popRecyLly?.background = drawable
                    helper?.setTextColor(R.id.popRecyCode, mContext.getColor(R.color.white))
                    helper?.setTextColor(R.id.popRecyoriginAddress, mContext.getColor(R.color.white))
                    helper?.setTextColor(R.id.popRecydestinationAddress, mContext.getColor(R.color.white))
                    helper?.setTextColor(R.id.popRecyorderStatus, mContext.getColor(R.color.white))
                    helper?.setTextColor(R.id.popRecyverify, mContext.getColor(R.color.white))
                }

                7 -> {
                    helper?.setText(R.id.popRecyorderStatus, "行程结束")
                }

                8 -> {
                    helper?.setText(R.id.popRecyorderStatus, "已取消")
                }

                9 -> {
                    helper?.setText(R.id.popRecyorderStatus, "已退款")
                }
            }

        }

        override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View?, position: Int) {
//            view?.findViewById<LinearLayout>(R.id.popRecyLly)?.setBackgroundColor(getColor(R.color.green3))
//            view?.findViewById<TextView>(R.id.popRecyCode)?.setTextColor(getColor(R.color.white))
//            view?.findViewById<TextView>(R.id.popRecyoriginAddress)?.setTextColor(getColor(R.color.white))
//            view?.findViewById<TextView>(R.id.popRecydestinationAddress)?.setTextColor(getColor(R.color.white))
//            view?.findViewById<TextView>(R.id.popRecyorderStatus)?.setTextColor(getColor(R.color.white))
//            view?.findViewById<TextView>(R.id.popRecyverify)?.setTextColor(getColor(R.color.white))
//            mapActivity.showLoading()
            val item = adapter.getItem(position) as BQueryDriverTransitOrderListBean
            //确认当点订单
//            mMapViewModel.getOnTransit(item.orderId, mMapViewModel.queryPassengerBySite.value?.siteId?.toInt()!!, siteLatitude.toString(), siteLongitude.toString())

            dismiss()
        }
    }
}